<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const minimumCost = cost => {
      cost.sort((a, b) => b - a);
      let spend = 0;
      const len = cost.length;
      for (let i = 1; i <= len; i++) {
        if (i % 3 === 0) continue;
        spend += cost[i - 1];
      }
      return spend;
    };
    console.log(minimumCost([6, 5, 7, 9, 2, 2]))
  </script>
</body>

</html>